<?php
/**
 * 通过例子理解swoole进程结构
 */
//$process = new \Swoole\Process(function (\Swoole\Process $childProcess) {
//
//}, false);

$process = new swoole_process(function (swoole_process $childProcess) {
    // php命令的绝对路径
    $phpbin = '/usr/local/bin/php';
    // 执行脚本的绝对路径
    $script = __DIR__ . '/../01_网络通信/01_http/01_http_server.php';
    $childProcess->exec($phpbin, [$script]);
    // 子进程内输出
//    $childProcess->write('你看到这行文字了吗') . PHP_EOL;
}, true); // 第二个参数为true,输出到屏幕,为false,不输出到屏幕

// 子进程id
$pid = $process->start();

echo $pid . PHP_EOL;
echo $process->read() . PHP_EOL;

// 等待父进程结束后回收子进程
swoole_process::wait();

// netstat -nltp | grep 9502
// ps aux | grep process_exec  查看进程,假如进程id为44
// pstree -p 44 查看进程树
// 父进程   master     manager   worker/04_task
//   |         |          |        |
//php(44)---php(45)---php(46)-+-php(49)
//                   |         `-php(50) ----worker/04_task
//                   |
//                   |-php(51) ---reactor
// ps atf | grep 01_http_server 查看进程之间的关系链

// https://www.jianshu.com/p/f91aaee75aa5
// https://blog.csdn.net/qq2942713658/article/details/82626577